const app = getApp()
Page({

  data: {
    tab1:true,
    tab2:false,
    current: 'tab1' ,
    coachInfo:[]
  },
  onLoad: function (options) {
    let that = this
    console.log(options.id)
    wx.request({
      url: app.url + '/weiapp/api/getCoachDetail',
      data:{id:options.id},
      success: function (res) {
        if (res.data.code != 200) {
          wx.showToast({
            title: '错误代码:' + res.data.code,
            icon: 'none',
            duration: 5000
          })
        }
        else {
          console.log(res.data.data)
          that.setData({
            coachInfo: res.data.data
          }),
          wx.setStorageSync('coachInfo_' + options.id,res.data.data )
        }
      }
    })

  },
  handleChange({ detail }) {
    var index = detail.key
    this.setData({
      current: detail.key
    });
    if (index == 'tab1') {
      this.setData({
        tab1: true,
        tab2: false
      })
    }
    else if (index == 'tab2') {
      this.setData({
        tab1: false,
        tab2: true
      })
    }
  },
  goCoachPhotos(even){
    wx.navigateTo({
      url: '../coach_photos/coach_photos?id=' + even.currentTarget.dataset.coach_id,
    })
  },
  goCoachIntro(even){
    wx.navigateTo({
      url: '../coach_intro/coach_intro?id='+even.currentTarget.dataset.coach_id,
    })
  },
  goProductDetail(even){
    console.log(even)
    wx.navigateTo({
      url: '../product_detail/product_detail?product_id=' + even.currentTarget.dataset.product_id + '&coach_id=' + even.currentTarget.dataset.coach_id + '&img=' + even.currentTarget.dataset.img,
    })
  }   
})